import requests

# 下载文件
direct_url = "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/direct-list.txt"
google_cn_url = "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/google-cn.txt"
windows_update_url = "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/win-update.txt"
apple_cn_url = "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/apple-cn.txt"
proxy_url = "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/proxy-list.txt"
gfw_url = "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/gfw.txt"

direct_list = requests.get(direct_url).text.splitlines() + requests.get(google_cn_url).text.splitlines() + requests.get(windows_update_url).text.splitlines() + requests.get(apple_cn_url).text.splitlines()
proxy_list = requests.get(proxy_url).text.splitlines() + requests.get(gfw_url).text.splitlines()

# 处理文件内容
def process_lines(lines, dns_address):
    result = []
    for line in lines:
        if line.startswith("full:"):
            line = line[5:]
        elif line.startswith("regexp:"):
            continue
        result.append(f"[/{line}/] {dns_address}")
    return result

direct_processed = process_lines(direct_list, "100.125.1.250 100.125.136.29")
proxy_processed = process_lines(proxy_list, "tls://dns.sgp.hicn.site")

# 合并文件内容
combined_lines = ["100.125.1.250"] + direct_processed + proxy_processed

# 写入结果到文件
with open("autodns_list.txt", "w") as file:
    file.write("\n".join(combined_lines))
